package com.example.jeecgboot.utils;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Redis工具类
 *
 * @author ichaoge
 */
@Component
public class RedisUtils {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;


    public void setObject(String key, Object value) {
        setObject(key, value, null);
    }

    public void setObject(String key, Object value, Long time) {
        redisTemplate.opsForValue().set(key, value);
        if (time != null) {
            redisTemplate.expire(key, time, TimeUnit.SECONDS);
        }
    }

    public Object getObject(String key) {
        return redisTemplate.opsForValue().get(key);
    }

}
